function checkAll(strItemName, value) {
	var x=document.getElementsByName(strItemName);
	for (var i=0; i<x.length; i++) {
	  	if (value == 1 && !x[i].disabled) {
			if( !x[i].checked ) x[i].checked = 'checked';
		} else {
			if(x[i].checked) x[i].checked = '';
		}
	}
}

function getItemsChecked(strItemName, sep) {
	var x=document.getElementsByName(strItemName);
	var p="";
	for(var i=0; i<x.length; i++) {
		if(x[i].checked) {
			p += x[i].value + sep;
		}
	}
	var result = (p != '' ? p.substr(0, p.length - 1) : '');
	return result;
}

$Behavior.loadJs = function() {	
    $('#send-button').click(function(evt) {
        var provider = $('#provider').val();
        var total = 0;
        var x=document.getElementsByName('items[]');
        for(var i=0; i<x.length; i++) {
            if(x[i].checked) {
                total++;
            }
        }
		if (total <= 0) {
			return false;
		}
		if (provider == 'linkedin' && total > 10) {
			alert('There are ' + total + ' contacts selected now.\nPlease select a maximum of 10 contacts to invite.');
			return false;
		}
        tb_show("", $.ajaxBox('contactimporter.sendPopup', "width=400&total="+total+'&provider='+provider));
   });
   $('#sendall-button').click(function(evt) {          
        var provider = $('#provider').val();        
        var friends_count = $('#friends_count').val();        
        tb_show("", $.ajaxBox('contactimporter.sendallPopup', "width=400" + "&provider=" + provider + "&friends_count=" + friends_count));
   });
}